import {
	trUrl
} from "../baseUrl.js";
import store from '../../../store/index.js';

const reportGet = function(url) {
	return function(params) {
		return new Promise((resolve, reject) => {
			// console.log(store.state.mdApprove.token,'store.state.mdApprove.token')
			uni.request({
				url: trUrl + url,
				method: 'get',
				header: {
					Authorization: store.state.mdApprove.token,
				},
				data: params,
				success: res => {
					// console.log('*********GET-orderp请求: ', res)
					if (url === '/api/user/update/icon') {
						resolve(res)
					} else if (res && res.statusCode === 200) {
						resolve(res.data.data)
					} else {
						reject(res)
					}
				},
				fail: err => {
					console.log(err)
					reject(err)
				}
			})
		})
	}
};


const reportPost = function(url) {
	return function(params) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: trUrl + url,
				method: 'post',
				header: {
					Authorization: store.state.mdApprove.token,
				},
				data: params,
				success: res => {
					// console.log('*********POST-orderp请求: ', res)
					
				 if (res && res.statusCode === 200) {
						if (res.data.success) {
							resolve(res.data.data)
						} else {
							reject(res.data)
						}
					} else {
						reject(res.data)
					}
				},
				fail: err => {
					console.log(err)
					reject(err)
				}
			})
		})
	}
};

const uploadUrl = trUrl + '/zhatu/file/upload'
const getOrgUserListUrl = trUrl + '/api/user/list'

export {
	reportGet,
	reportPost,
	uploadUrl
}
